<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <title>Document</title>
    <style>
        #box{
            width: 150px;
            height: 100px;
            background-color: green;
        }
        html,body,#app{
            width: 100%;
            height: 100%;
        }

        #app{
            position: relative;
        }
        img {
            width: 250px;
            height: 150px;
        }

    </style>
</head>
<body>
    
    <!-- 指令联系 -->
    <div id="app" v-on:keyup="moveimg">
       
        <!-- 为按钮绑定监听事件 -->
        <button v-on:click="halo">{{button}}</button>
        <!-- 当 v-if这个值为 false 的时候不会显示，当为true 的时候显示 -->
        <div id="box" v-if="isShow"></div>
        <img src="./a.jpg">

    </div>

    <script>
        var vue = new Vue({
            el:"#app",
            data:{
                button: "点击去掉绿色",
                isShow: true
            },
            methods: {
                halo() {
                    if(this.isShow == true){
                        this.isShow = false
                        this.button = "点击变绿";
                        return
                    }

                    this.isShow = true
                    this.button = "点击去掉绿色";
                },

                moveimg(event){
                    console.log(event)
                }
            }
        })
    </script>
</body>
</html>